#ifndef BF
#define BF

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>


#define BF_READ (O_RDONLY)
#define BF_WRITE (O_WRONLY | O_TRUNC | O_CREAT)
#define BUFFSIZE 32768

typedef struct _bitiob {
  int count;  // nombre de bits restant
  char *ptr;  // octet courrant
  char *base; // debut du tampon
  int fd;     // descripteur de fichier soujacent
  int flags;
} *bf_stream;

bf_stream bf_stream_new (int fd);
bf_stream bf_open (char *path, int mode);
int bf_close (bf_stream bf);
void bf_fillbuff (bf_stream bf);
int bf_flush (bf_stream bf);
int bf_putbit (bf_stream bf, int b);
int bf_getbit (bf_stream bf);
int bf_putchar (bf_stream bf, int c);
int bf_getchar (bf_stream bf);

int bf_isaligned (bf_stream bf);
int bf_align (bf_stream bf);

#endif
